var gulp=require('gulp');
var uglify=require('gulp-uglify');
var concat=require('gulp-concat');
var replace=require('gulp-replace');
var gulpif=require('gulp-if');
var angularTemplateCache=require('gulp-angular-templatecache');
var less=require('gulp-less');

gulp.task('develop:lib:js', function() {
    var libs=[
        'bower_components/jquery/dist/jquery.min.js',
        'bower_components/angular/angular.min.js',
        'bower_components/angular-route/angular-route.min.js',
        'bower_components/semantic/dist/semantic.min.js',
        'bower_components/jquery.cookie/jquery.cookie.js',
        'bower_components/nice-validator/dist/jquery.validator.min.js',
        'bower_components/nice-validator/dist/local/zh-CN.js',
        'bower_components/nprogress/nprogress.js',
        'bower_components/sweetalert/dist/sweetalert.min.js',
        'bower_components/echarts/dist/echarts.min.js'
    ];

    return gulp.src(libs)
        .pipe(concat('lib.js'))
        .pipe(gulp.dest('dist/compile/lib'));
});

gulp.task('develop:lib:css', function() {
    var libs=[
        'bower_components/semantic/dist/semantic.min.css',
        'bower_components/sweetalert/dist/sweetalert.css',
        'bower_components/nprogress/nprogress.css',
        'bower_components/animate.css/animate.min.css'
    ];

    return gulp.src(libs)
        //替换谷歌字体
        .pipe(replace('https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic&subset=latin',''))
        .pipe(concat('lib.css'))
        .pipe(gulp.dest('dist/compile/lib'));
});

gulp.task('develop:lib:static', function() {
    var libs=[
        'bower_components/semantic/dist/themes*/default*/**/*'
    ];

    return gulp.src(libs)
        .pipe(gulp.dest('dist/compile/lib'));
});

gulp.task('develop:lib',['develop:lib:js','develop:lib:css','develop:lib:static'], function() {

});

gulp.task('develop:app:template', function() {
    return gulp.src('src/**/template/*.html')
        .pipe(angularTemplateCache({
            root:'/',
            module:'templateCache',
            standalone: true
        }))
        .pipe(concat('template.js'))
        .pipe(gulp.dest('dist/compile'));
});

gulp.task('develop:app:core', function() {
    var modules=[
        '!src/core/app_intro.js',
        '!src/core/app_outro.js',
        '!src/core/app_core_intro.js',
        '!src/core/app_core_outro.js',
        'src/core/util/**/*.js',
        'src/core/ui/**/*.js',
        'src/core/**/*.js'
    ];

    return gulp.src(modules)
        .pipe(concat('core.js'))
        .pipe(gulp.dest('dist/compile'));
});

gulp.task('develop:app:app', function() {
    var modules=[
        'src/**/service/*.js',
        'src/**/directive/*.js',
        'src/**/filter/*.js',
        'src/**/controller/*.js',
        'src/**/router/*.js'
    ];

    return gulp.src(modules)
        .pipe(concat('app.js'))
        .pipe(gulp.dest('dist/compile'));
});

gulp.task('develop:app:js',['develop:app:template','develop:app:core','develop:app:app'], function() {
    var modules=[
        'src/core/app_intro.js',
        'src/core/app_core_intro.js',
        'dist/compile/core.js',
        'src/core/app_core_outro.js',
        'dist/compile/app.js',
        'src/core/app_outro.js'
    ];

    return gulp.src(modules)
        .pipe(concat('app.js'))
        .pipe(gulp.dest('dist/compile'));
});

gulp.task('develop:app:static', function() {
});

gulp.task('develop:app:css', function() {
    var modules=[
        'src/**/less/*.less'
    ];

    return gulp.src(modules)
        .pipe(less())
        .pipe(concat('app.css'))
        .pipe(gulp.dest('dist/compile'));
});

gulp.task('develop:app:img', function() {
    return gulp.src(['src/**/image/*'])
        .pipe(gulp.dest('dist/compile'));
});

gulp.task('develop:app',['develop:app:js','develop:app:css','develop:app:img','develop:app:static'], function() {
    return gulp.src(['src/*.html'])
        .pipe(gulp.dest('dist/compile'));
});